package com.magnificent.atlantis.common.entity;

import com.magnificent.commons.db.datasource.ObjectEntity;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import java.io.Serializable;
import java.util.Date;

/**
 * User: Babanin
 * Date: 26.03.2009
 * Time: 12:22:32
 */

@Entity()
@Table(name = "user")
@XmlRootElement(name = "serverUser")
public class ServerUser extends ObjectEntity implements Serializable, Comparable<ServerUser> {
    private String login;
    private String password;
    private String clearPassword;

    private String name;
    private String surname;
    private Date lastUpdate;

    private boolean baned;

    public ServerUser() {
    }

    @Basic()
    @Column(name = "login")
    @XmlAttribute()
    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    @Basic()
    @Column(name = "password")
    @XmlTransient()
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Basic()
    @Column(name = "name")
    @XmlAttribute()
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Basic()
    @Column(name = "surname")
    @XmlAttribute()
    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    @Basic()
    @Column(name = "lastUpdate")
    @XmlAttribute()
    public Date getLastUpdate() {
        return lastUpdate;
    }

    public void setLastUpdate(Date lastUpdate) {
        this.lastUpdate = lastUpdate;
    }

    @Basic()
    @Column(name = "baned")
    @XmlAttribute()
    public boolean isBaned() {
        return baned;
    }

    public void setBaned(boolean baned) {
        this.baned = baned;
    }

    @Basic()
    @Column(name = "clearPassword")
    @XmlAttribute()
    public String getClearPassword() {
        return clearPassword;
    }

    public void setClearPassword(String clearPassword) {
        this.clearPassword = clearPassword;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof ServerUser)) return false;

        ServerUser that = (ServerUser) o;

        if (baned != that.baned) return false;
        if (lastUpdate != null ? !lastUpdate.equals(that.lastUpdate) : that.lastUpdate != null) return false;
        if (login != null ? !login.equals(that.login) : that.login != null) return false;
        if (name != null ? !name.equals(that.name) : that.name != null) return false;
        if (password != null ? !password.equals(that.password) : that.password != null) return false;
        if (surname != null ? !surname.equals(that.surname) : that.surname != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = login != null ? login.hashCode() : 0;
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (surname != null ? surname.hashCode() : 0);
        result = 31 * result + (lastUpdate != null ? lastUpdate.hashCode() : 0);
        result = 31 * result + (baned ? 1 : 0);
        return result;
    }

    public int compareTo(ServerUser o) {
        return o.login.compareTo(this.login);
    }
}
